package com.muyu.danmo.service.impl;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoCommunity;
import com.muyu.danmo.domain.DanmoCommunityCommentLike;
import com.muyu.danmo.domain.DanmoCommunityLike;
import com.muyu.danmo.mapper.DanmoCommunityCommentLikeMapper;
import com.muyu.danmo.service.IDanmoCommunityCommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 社区评论点赞Service业务处理层
 *
 * @author : kunzong
 * @date : 2024-11-19
 */
@Service
public class DanmoCommunityCommentLikeServiceImpl implements IDanmoCommunityCommentLikeService {

    @Autowired
    private  DanmoCommunityCommentLikeMapper danmoCommunityCommentLikeMapper;


    /**
     * 判断用户是否已点赞
     *
     * @param id
     * @return
     */
    @Override
    public Result isCollect(Long id) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        DanmoCommunityCommentLike danmoCommunityCommentLike = danmoCommunityCommentLikeMapper.selectDanmoCollectMaterialByIdAndUserId(id, loginUser.getUserid());
        if (danmoCommunityCommentLike == null) {
            danmoCommunityCommentLike = new DanmoCommunityCommentLike();
            danmoCommunityCommentLike.setUserId(loginUser.getUserid());
            danmoCommunityCommentLike.setPostId(id);
            danmoCommunityCommentLike.setCreateTime(DateUtils.getNowDate());
            danmoCommunityCommentLike.setLikeName("true");
            danmoCommunityCommentLikeMapper.insertDanmoCommunityCommentLike(danmoCommunityCommentLike);
            return Result.success(id, "点赞成功");
        } else {
            danmoCommunityCommentLikeMapper.deleteDanmoCommunityCommentLikeById(id);
            return Result.success(1,"取消点赞成功");
        }
    }
}